package test02;

import java.util.Arrays;

public class demo04 {
    public static void main(String[] args) {
        int oldArr[]={1,3,4,5,0,0,6,6,0,5,4,7,6,7,0,5};
        int count=0;
        for(int i=0;i<oldArr.length;i++){
            if(oldArr[i]==0){
                count++;
            }
        }
        int newArr[]=new int[oldArr.length-count];
        int j=0;
        for (int i = 0; i < oldArr.length; i++) {
            if(oldArr[i]!=0){
                newArr[j]=oldArr[i];
                j++;
            }
        }
        System.out.println("oldArr为:"+ Arrays.toString(oldArr));
        System.out.println("newArr为:"+ Arrays.toString(newArr));
    }
}
